package com.autonavi.yunda.yunji.common.utils.geo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GeoLatLon {
    public double lat;
    public double lon;

    public GeoLatLon() {
        lat = lon = 0.0;
    }

    public GeoLatLon(double lat, double lon) {
        this.lat = lat;
        this.lon = lon;
    }

    public GeoLatLon(String lat, String lon) {
        this.lat = Double.parseDouble(lat);
        this.lon = Double.parseDouble(lon);
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLon() {
        return lon;
    }

    public void setLon(double lon) {
        this.lon = lon;
    }


    /**
     * 将x1 y1,x2 y2,x3 y3格式的数据转为GeoLatLon数组形式
     * @param wkt
     * @return
     */
    public static ArrayList<GeoLatLon> wktTansGeoLatLon(String wkt) {
        List<String> pointList = Arrays.asList(wkt.split(","));
        ArrayList<GeoLatLon> wktPoints = new ArrayList<>();
        for (String point : pointList) {
            String[] pintXY = point.split(" ");
            wktPoints.add(new GeoLatLon(pintXY[1], pintXY[0]));
        }
        return wktPoints;
    }

    public static ArrayList<GeoLatLon> wktTansGeoLatLon2(List<String> pointList) {
//        List<String> pointList = Arrays.asList(wkt.split(","));
        ArrayList<GeoLatLon> wktPoints = new ArrayList<>();
        for (String point : pointList) {
            String[] pintXY = point.trim().split(" ");
            wktPoints.add(new GeoLatLon(pintXY[1], pintXY[0]));
        }
        return wktPoints;
    }
}
